package com.yuntai.pms.model.result;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;

/**
 * @ClassName: PageResult
 * @Description: 分页结果
 * @author 王勇琳
 * @date 2017年7月21日 上午10:30:41
 * @param <T>
 */
public class PageResult<T> implements Serializable {
	private static final long serialVersionUID = -5088185464980438586L;

	private boolean result = true;

	private String message = "";

	private Long total = 0L;

	private List<T> rows = new ArrayList<T>();

	public PageResult() {
		this.result = true;
	}

	public PageResult(boolean result, String message, Long total, List<T> rows) {
		this.result = result;
		this.message = message;
		this.total = total;
		this.rows = rows;
	}

	public static <T> PageResult<T> create(boolean result, String message, Long total, List<T> rows) {
		return new PageResult<T>(result, message, total, rows);
	}

	public static <T> PageResult<T> create(String message, Long total, List<T> rows) {
		return new PageResult<T>(true, message, total, rows);
	}

	public static <T> PageResult<T> create(Long total, List<T> rows) {
		return new PageResult<T>(true, "", total, rows);
	}

	public static <T> PageResult<T> create(List<T> rows) {
		return new PageResult<T>(true, "", (rows == null) ? 0L : rows.size(), rows);
	}

	public static <T> PageResult<T> create(boolean result, String message) {
		return new PageResult<T>(result, message, 0L, null);
	}

	public boolean isResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}
}
